#include<iostream>
#include<vector>
#include<queue>
#include<cstring>
#include<cmath>
#include<map>
#include<set>
#include<cstdio>
#include<algorithm>
#define debug(a) cout<<#a<<"="<<a<<endl;
using namespace std;
const int maxn=2e5+1000;
typedef long long LL;
const LL mod=1e9+7;
inline LL read(){LL x=0,f=1;char ch=getchar();	while (!isdigit(ch)){if (ch=='-') f=-1;ch=getchar();}while (isdigit(ch)){x=x*10+ch-48;ch=getchar();}
return x*f;}
char str[maxn];
LL dp[maxn][3];
int main(void){
   cin.tie(0);std::ios::sync_with_stdio(false);
   LL n;cin>>n;
   cin>>(str+1);
   LL temp=1;
   for(LL i=1;i<=n;i++){
       for(LL k=0;k<3;k++) dp[i][k]=dp[i-1][k]%mod;
       if(str[i]=='a') dp[i][0]=(dp[i-1][0]%mod+temp)%mod;
       if(str[i]=='b') dp[i][1]=(dp[i-1][0]%mod+dp[i-1][1]%mod)%mod;
       if(str[i]=='c') dp[i][2]=(dp[i-1][1]%mod+dp[i-1][2]%mod)%mod;
       if(str[i]=='?'){
           dp[i][0]=(3*dp[i-1][0]%mod+temp)%mod;
           dp[i][1]=(3*dp[i-1][1]%mod+dp[i-1][0]%mod)%mod;
           dp[i][2]=(3*dp[i-1][2]%mod+dp[i-1][1]%mod)%mod;
           temp=temp*3%mod;
       }
   }
   cout<<dp[n][2]<<"\n";
   return 0;
}
